/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Client_GUI.SavingType;

import Client_GUI.Customer.JP_SearchCustomer;
import Client_GUI.Unity;
import Interface.IRemoteCustomer;
import Interface.IRemoteSavingType;
import Server.DTO.Customer_DTO;
import Server.DTO.SavingType_DTO;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

/**
 *
 * @author 10520_000
 */
public class JP_SearchSavingType extends org.jdesktop.swingx.JXPanel {

    Registry registry;
    IRemoteSavingType rsavingtype;
    table_SavingType table = new table_SavingType();

    /**
     * Creates new form JP_AddCusomer
     */
    public JP_SearchSavingType() throws RemoteException, NotBoundException {
        initComponents();
        registry = LocateRegistry.getRegistry("127.0.0.1");
        rsavingtype = (IRemoteSavingType) registry.lookup("SavingType");
        table.setTable(jTable_SavingType);
        LoadTable();
    }

    public void LoadTable() throws RemoteException, NotBoundException {
        this.jTable_SavingType.setModel(table.LoadTable());
    }

    public void LoadTableSearch(SavingType_DTO info) throws RemoteException, NotBoundException {
        this.jTable_SavingType.setModel(table.LoadTableSearch(info));
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel2 = new javax.swing.JPanel();
        jPanel4 = new javax.swing.JPanel();
        jLabel7 = new javax.swing.JLabel();
        cbo_TenLoaiTietKiem = new javax.swing.JComboBox();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable_SavingType = new javax.swing.JTable();

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Thông tin khách hàng"));

        jLabel7.setFont(new java.awt.Font("Times New Roman", 0, 15)); // NOI18N
        jLabel7.setText("Tên Loại Tiết Kiệm");

        cbo_TenLoaiTietKiem.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "XEM TAT CA", "CO KY HAN", "KHONG KY HAN" }));
        cbo_TenLoaiTietKiem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbo_TenLoaiTietKiemActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel7)
                .addGap(18, 18, 18)
                .addComponent(cbo_TenLoaiTietKiem, javax.swing.GroupLayout.PREFERRED_SIZE, 203, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(cbo_TenLoaiTietKiem, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(79, Short.MAX_VALUE))
        );

        jTable_SavingType.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(jTable_SavingType);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGap(259, 259, 259))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 929, Short.MAX_VALUE)
                        .addContainerGap())))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 419, Short.MAX_VALUE)
                .addGap(76, 76, 76))
        );

        jPanel4.getAccessibleContext().setAccessibleName("Thông Tin Loại Tiết Kiệm");
    }// </editor-fold>//GEN-END:initComponents

    private void cbo_TenLoaiTietKiemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbo_TenLoaiTietKiemActionPerformed
        // TODO add your handling code here:
        SavingType_DTO info = new SavingType_DTO();
        if (cbo_TenLoaiTietKiem.getSelectedItem().toString().compareTo("XEM TAT CA") == 0) {
            try {
                LoadTable();
            } catch (RemoteException ex) {
                Logger.getLogger(JP_SearchSavingType.class.getName()).log(Level.SEVERE, null, ex);
            } catch (NotBoundException ex) {
                Logger.getLogger(JP_SearchSavingType.class.getName()).log(Level.SEVERE, null, ex);
            }
        } else {
            info.setName(cbo_TenLoaiTietKiem.getSelectedItem().toString());
            try {
                LoadTableSearch(info);
            } catch (RemoteException ex) {
                Logger.getLogger(JP_SearchCustomer.class.getName()).log(Level.SEVERE, null, ex);
            } catch (NotBoundException ex) {
                Logger.getLogger(JP_SearchCustomer.class.getName()).log(Level.SEVERE, null, ex);
            }
        }

    }//GEN-LAST:event_cbo_TenLoaiTietKiemActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox cbo_TenLoaiTietKiem;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable_SavingType;
    // End of variables declaration//GEN-END:variables
}
